# 对label 的最后一项（detect的obj）删除
import os

folder_path = 'D:\labelming_data\labels_obj'

# 遍历文件夹中的所有文件
for filename in os.listdir(folder_path):
    if filename.endswith('.txt'):
        file_path = os.path.join(folder_path, filename)

        # 读取文件内容
        with open(file_path, 'r') as f:
            lines = f.readlines()

        # 删除每行最后一列的数据
        new_lines = []
        for line in lines:
            columns = line.strip().split()  # 假设数据是空格分隔的
            new_line = ' '.join(columns[:-1]) + '\n'  # 删除最后一列
            new_lines.append(new_line)

        # 将修改后的内容写回文件
        with open(file_path, 'w') as f:
            f.writelines(new_lines)

print("Done!")
